﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;

namespace Bes.Swsp.ToolBox
{
  public static class RasterUtility
  {
    public static object GetPixelValue(IRaster raster, IPoint location)
    {
      IRaster2 raster2 = raster as IRaster2;
      int col = raster2.ToPixelColumn(location.X);
      int row = raster2.ToPixelRow(location.Y);
      return raster2.GetPixelValue(0, col, row);
    }

    public static double GetPixelValueDouble(IRaster raster, IPoint location)
    {
      object pixelValue = GetPixelValue(raster, location);
      if (pixelValue == null)
        return double.NaN;
      else
        return Convert.ToDouble(pixelValue);
    }

    public static int GetPixelValueInt(IRaster raster, IPoint location)
    {
      return Convert.ToInt32(GetPixelValue(raster, location));
    }
  }
}
